﻿using CardMaker.Library.Models;
using System.Linq.Expressions;

namespace CardMaker.Library.Services;

public class CardTemplateService : ICardTemplateService {
    private readonly ICardTemplateStorage _cardTemplateStorage;
    private readonly IPreferenceStorage _preferenceStorage;

    public CardTemplateService(IPreferenceStorage preferenceStorage,
        ICardTemplateStorage cardTemplateStorage) {
        _preferenceStorage = preferenceStorage;
        _cardTemplateStorage = cardTemplateStorage;
    }

    public Task<CardTemplate> GetCardTemplateAsync(int id) {
        return _cardTemplateStorage.GetCardTemplateAsync(id);
    }

    public async Task<IEnumerable<CardTemplate>> GetCardTemplatesAsync()
    {
        Expression<Func<CardTemplate, bool>> allTemplatesExpression = p => true;

        // 跳过 0 个记录，获取尽可能多的记录
        int skip = 0;

        // 通过一个大的值来确保获取尽可能多的记录
        int take = int.MaxValue;

        return await _cardTemplateStorage.GetCardTemplatesAsync(allTemplatesExpression, skip, take);
    }


    public Task AddCardTemplateAsync(CardTemplate cardTemplate, List<SideImage> sideImages, List<TextFrame> textFrames) {
        return _cardTemplateStorage.AddCardTemplateAsync(cardTemplate,sideImages,textFrames);
    }
}